# coding=utf-8
import csv

base_file_path = u"C:\\Users\\LENOVO\Documents\\Tencent Files\\411213159\\FileRecv\\data\\data\\"
file_name = u"professor_base_data.csv"
f = open(base_file_path + file_name, "rb")
csvDict = csv.DictReader(f)
i = 0
csvHeader = None
rowDict = []
for row in csvDict:
    newrow = {"ZJBH":row.get("ZJBH",""),"ZJXM":row.get("ZJXM",""),"ZJXY":row.get("ZJXY",""),"ZJXK":row.get("ZJXK",""),"ZJXX":row.get("ZJXX","")}
    rowDict.append(newrow)
    if i == 0:
        csvHeader = newrow
    elif 0 == i % 5000:
        sf = open(base_file_path+"data_block_" + str(int(i / 5000)) + ".csv", "wb")
        writer = csv.DictWriter(sf, fieldnames=csvHeader)
        writer.writeheader()
        for arow in rowDict:
            writer.writerow(arow)
        del rowDict[:]
    i+=1

sf = open(base_file_path + "data_block_" + str(int(i / 5000)+1) + ".csv", "wb")
writer = csv.DictWriter(sf, fieldnames=csvHeader)
writer.writeheader()
for arow in rowDict:
    writer.writerow(arow)
del rowDict[:]
